package com.xingkeduo.configuration.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @description 初始拦截器
 * @author 中文输入法发挥不稳定的刘川
 * @date 19-3-12 下午2:45
 */
@Component
public class BasePathInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		String basePath	= request.getContextPath();

		if (!basePath.startsWith("/")) {
			basePath = "/" + basePath;
		}
		if (!basePath.endsWith("/")) {
			basePath += "/";
		}

		request.getSession().setAttribute("basePath", basePath);

		return true;
	}

}
